//懒汉模式(多线程版)
public class LazySingleton {

    private static LazySingleton instance = null;

    private LazySingleton() {
        // 私有构造方法，防止其他类通过构造函数创建实例对象
    }
    public static LazySingleton getInstance() {
       if (instance == null) {
           synchronized (LazySingleton.class) {
               if (instance == null) {
                   instance = new LazySingleton();
               }
           }
       }
       return instance;
    }
}
//懒汉模式(单线程版)
class LazySingleton2 {

    private static LazySingleton2 instance = null;

    private LazySingleton2() {
        // 私有构造方法，防止其他类通过构造函数创建实例对象
    }

    public static LazySingleton2 getInstance() {
        if (instance == null) {
            instance = new LazySingleton2();

        }
        return instance;
    }
}
